import { PausableTimeout } from "./PausableTimeout";

export class TimeoutManager {
  private static timeouts: PausableTimeout[] = [];

  public static setTimeout(callback: () => void, delay: number): PausableTimeout {
    const timeout = new PausableTimeout(callback, delay).start();
    this.timeouts.push(timeout);
    return timeout;
  }

  public static pauseAll(): void {
    this.timeouts.forEach(timeout => timeout.pause());
  }

  public static resumeAll(): void {
    this.timeouts.forEach(timeout => timeout.resume());
  }

  public static removeTimeout(timeout: PausableTimeout): void {
    const index = this.timeouts.indexOf(timeout);
    if (index > -1) {
      this.timeouts.splice(index, 1);
    }
  }
}